package com.pengbei.enshrine.common.dialog.callback;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.pengbei.enshrine.R;
import com.pengbei.enshrine.network.bean.PermissionIntroduceModel;

import java.util.ArrayList;
import java.util.List;

public class PermissionIntroduceAdapter extends RecyclerView.Adapter {

    private Context context;
    private LayoutInflater mInflater;
    private List<PermissionIntroduceModel> dlist;

    public PermissionIntroduceAdapter(Context context, List<PermissionIntroduceModel> dlist) {
        this.context = context;
        mInflater = LayoutInflater.from(context);
        setList(dlist);
    }

    public void setList(List<PermissionIntroduceModel> dlist) {
        if (dlist != null) {
            this.dlist = dlist;
        } else {
            this.dlist = new ArrayList<PermissionIntroduceModel>();
        }
    }

    public void change(List<PermissionIntroduceModel> dlist) {
        setList(dlist);
        this.notifyDataSetChanged();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_permissionintroduce, parent, false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;

    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.tv_lp_name.setText(dlist.get(position).getName());
        viewHolder.tv_lp_content.setText(dlist.get(position).getContent());
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        LinearLayout ll_content;
        TextView tv_lp_name;
        TextView tv_lp_content;

        public ViewHolder(View itemView) {
            super(itemView);
            ll_content = (LinearLayout) itemView.findViewById(R.id.ll_content);
            tv_lp_name = (TextView) itemView.findViewById(R.id.tv_lp_name);
            tv_lp_content = (TextView) itemView.findViewById(R.id.tv_lp_content);
        }
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getItemCount() {
        return dlist.size();
    }



}